package com.jade.bss.db.impl;
 
import com.jade.bss.DbException;
import com.jade.bss.db.BaseFacade;
import com.jade.bss.db.JpaBaseDao;
import com.jade.framework.base.criterion.Criteria;
import com.jade.framework.base.util.PagingList;
import com.jade.framework.base.util.PagingResult;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 零售生态体系--智慧销售篇
 * User: JinYa 2009_jinya@163.com
 * Date: 2016-4-17
 * Time: 14:10
 * Version : 1.0
 * Remark:
 * History:
 */
public class BaseFacadeImpl implements BaseFacade {

    @Resource(name = "baseDao")
    private JpaBaseDao baseDao;

    @Transactional(propagation= Propagation.REQUIRED)
    public <T> void delete(Class<T> clazz, Object id) throws DbException {
        baseDao.delete(clazz, id);
    }

    @Transactional(propagation= Propagation.REQUIRED)
    public <T> void delete(Class<T> clazz, Object[] ids)throws DbException {
        baseDao.delete(clazz, ids);
    }


    public <T> List<T> getAll(Class<T> clazz)throws DbException {
        return baseDao.getAll(clazz);
    }

    public <T> T getById(Class<T> clazz, Object id)throws DbException {
        return baseDao.getById(clazz, id);
    }

    public <T> List<T> getByIds(Class<T> clazz, Object[] ids)throws DbException{
        return baseDao.getByIds(clazz, ids);
    }

    @Transactional(propagation=Propagation.REQUIRED)
    public void save(Object entity)throws DbException {
        baseDao.save(entity);
    }

    @Transactional(propagation=Propagation.REQUIRED)
    public <T> void batchSave(List<T> entitys)throws DbException{
        baseDao.batchSave(entitys);
    }

    @Transactional(propagation=Propagation.REQUIRED)
    public void update(Object entity)throws DbException {
        baseDao.update(entity);
    }
    @Transactional(propagation=Propagation.REQUIRED)
    public <T> PagingList<T> queryEntity(Class<T> entityClass, Criteria criteria)throws DbException{
        return baseDao.queryEntity(entityClass,criteria);
    }
    public <T> PagingList<T> queryEntity(Class<T> entityClass, Object entity,int page,int size) throws DbException{
        return baseDao.queryEntity(entityClass,new Criteria());
    }
    public <T> PagingList<T> queryEntity(Class<T> entityClass, Object entity,int page,int size,String key) throws DbException{
        return baseDao.queryEntity(entityClass,new Criteria());
    }
    public PagingResult queryEntity(Object entity,int page,int size,String keys,String... orders) throws DbException,IllegalAccessException, InstantiationException{
         return null;
    }
}
